//
//  KLMSettingController.swift
//  KLM_GN
//
//  Created by Nic on 2025/3/4.
//

import UIKit

class KLMSettingController: KLMBaseRowController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidLoadConfig() {
        super.viewDidLoadConfig()
        rowItems = KLMRowItem.mineSettingItems()
    }
    
    override func tableViewDidSelect(item: KLMRowItem, at: IndexPath, on: UITableView) {
        super.tableViewDidSelect(item: item, at: at, on: on)
        
        var childVc: RowTitleReceivable? = nil
        switch item.type {
        case .personal:
            childVc = KLMPersonalController()
        case .accountSecurity:
            childVc = KLMAccountSecurityController()
        case .update:
            childVc = KLMAllDevicesController()
        case .appNotify:
            childVc = KLMAppNotifyController()
        case .moreLanguage:
            childVc = KLMLanguageController()
        case .authorization:
            childVc = KLMAuthorizationController()
        case .theme:
            childVc = KLMThemePickController()
        case .about:
            childVc = KLMAboutController()
        case .privacyPolicy:
            childVc = KLMPrivacyController()
        case .networkDiagnosis:
            childVc = KLMNetworkDiagnosisController()
        case .clearCache:
            let vc = KLMBaseModalController(type: .tipOnlyTitle, operTitle: "清理缓存后，不会丢失 你的设备数据和个人信息", confirmTitle: "立即清理", confirmBlock:  { text, type in
                print(text as Any, type)
            })
            modalVc(vc: vc)
            return
        case .logout:
            SVProgressHUD.show()
            KLMRequest.logout { response in
                SVProgressHUD.dismiss()
                KLMHomeMesh.logout()
                self.switchLoginVc()
            } failure: { error in
                SVProgressHUD.dismiss()
                KLMHttpShowError(error)
            }
            return
        default:
            break
        }
        
        guard let childVc = childVc else { return }
        childVc.titleText = item.title
        navigationController?.pushViewController(childVc as! UIViewController, animated: true)
    }
}
